#include "control.h"

unsigned char Temper_Read_Flag;	//温度读取标志位
unsigned char TMAX = 30, TMIN = 20;

void Temper_Read(void)
{
	if ( Temper_Read_Flag) {
		Temper_Read_Flag = 0;	//温度读取标志位清零
		rd_temperature();
	 } 	
}

//unsigned char Temper_Read(void)
//{
//	float Temp;
//	unsigned char Temper_return;
//	if (1 == Temper_Read_Flag)
//	{
//		Temper_Read_Flag = 0;	//温度读取标志位清零
//		DS18B20_ConvertT();	 	//温度转换
//		Temp = DS18B20_ReadT(); 	//温度读取
//		Temper_return = (unsigned char)Temp;
//	}	
//	return Temper_return;
//}


void Temper_Jiemian_1(unsigned char temperature)
{
	yi = 12;
	er = SMG_OFF_code;
	san = SMG_OFF_code;
	si = SMG_OFF_code;
	wu = SMG_OFF_code;
	liu = SMG_OFF_code;
	qi = temperature / 10;
	ba = temperature % 10;
}

void Param_Jiemian_2(void)
{
	yi = 29;
	er = SMG_OFF_code;
	san = SMG_OFF_code;
	si = TMAX / 10;
	wu = TMAX % 10;
	liu = SMG_OFF_code;
	qi = TMIN / 10;
	ba = TMIN % 10;
}

void DAC_Output_panduan(void)
{
	if (temp > TMAX)
	{
		PCF8591_DAC(282*4/5);	//DAC输出 4V
		P2 = 0x80;	// 1000 0000
		P0 = 0xFE;	//点亮第1个LED
	}
	else if (temp>=TMIN && temp<=TMAX)
	{
		PCF8591_DAC(282*3/5);	//DAC输出 3V
		P2 = 0x80;	// 1000 0000
		P0 = 0xFD;	//点亮第2个LED
	}
	else if (temp<TMIN)
	{
		PCF8591_DAC(282*2/5);	//DAC输出 2V
		P2 = 0x80;	// 1000 0000
		P0 = 0xFB;	//点亮第3个LED
	}
	
	if (TMAX<TMIN)	//用if单独判断参数是否有设置错误！！
	{
		P2 = 0x80;	// 1000 0000
		P0 = 0xF7;	//点亮第4个LED
	}
}


unsigned char uc_SEG_10ms;
unsigned int T_Read_count;
//定时器0中断服务函数
void Timer0_Rountine(void) interrupt 1
{
	static unsigned int Key4_T0Count0;
	
	T_Read_count++;
	if (T_Read_count >= 500)	//500ms 温度读取标志位置1
	{
		Temper_Read_Flag = 1;
		T_Read_count = 0;
		
	}
	
	
	if(++Key4_T0Count0 >= 10)
	{
		//执行操作
		uc_Key_flag = 0;
		Key4_T0Count0 = 0;	//软件复位
	}
	
}
